Fix #3658 .cargo/config prevents freshness (sort if sourced from HashMap)
authorNathanael Jones <nathanael.jones@gmail.com>
Tue, 7 Feb 2017 00:16:33 +0000 (17:16 -0700)
committerNathanael Jones <nathanael.jones@gmail.com>
Tue, 7 Feb 2017 00:16:33 +0000 (17:16 -0700)
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/custom_build.rs

index ec13b2a2e8af91118b3eee7a822b5822b1f9ec64..acc2fdf355ddfeef3170d33deb556c130b3096f4 100644 (file)
@@ -528,6 +528,10 @@ fn scrape_target_config(config: &Config, triple: &str)
                     output.metadata.push((k.clone(), val.to_string()));
                 }
             }
+
+            // We randomized the data source with HashMaps, so we must sort the resulting vectors
+            // to produce a deterministic result
+            output.sort();
         }
         ret.overrides.insert(lib_name, output);
     }
index ea3e0f98ca244ec78a5eb21cbd7633192c0b623e..4315598689b847144e805358b9b078864ee63d61 100644 (file)
@@ -406,6 +406,17 @@ impl BuildOutput {
         }
         Ok((library_paths, library_links))
     }
+
+    /// Sort the contents of the struct for consistent hashing. 
+    /// Suggested if populated from a HashMap instead of a order-preserving data source
+    pub fn sort(&mut self){
+        self.library_paths.sort();
+        self.library_links.sort();
+        self.cfgs.sort();
+        self.metadata.sort();
+        self.rerun_if_changed.sort();
+        self.warnings.sort();
+    }   
 }
 
 /// Compute the `build_scripts` map in the `Context` which tracks what build